#include <iostream>
#include <cstdlib>
#include <sstream>
#include <algorithm>

using namespace std;

int compare (const void * a, const void * b) {
	return ( *(int*)b - *(int*)a );
}

int main(void) {
	//C->Containers S->Specimens
	int C, S;
	string newLine;

	for(int set=1;getline(cin, newLine);set++) {
		stringstream ss;
		ss << newLine;
		ss >> C >> S;

		//Read Set Line
		ss.clear();
		getline(cin, newLine);
		ss << newLine;
		//Sp->Specimen array Ct->Container Array Cs->Container Sum
		int Sp[S], Ct[C][S], Cs[C];
		for(int i=0;i<C;i++) {
			Cs[i] = 0;
			for(int j=0;j<S;j++)
				Ct[i][j] = 0;
		}

		for(int i=0;i<S;i++)
			ss >> Sp[i];

		//Sort Specimens by Size
		qsort(Sp, S, sizeof(int), compare);

		for(int i=0;i<S;i++) {
			int min = 0;
			for(int j=1;j<C;j++)
				if(Cs[j] < Cs[min]) 
					min = j;
			Ct[min][i] = Sp[i];
			Cs[min] += Sp[i];
		}
		cout << "Set #" << set << endl;
		for(int i=0;i<C;i++) {
			cout << " " << i << ":  ";
			for(int j=0;j<S;j++)
				if(Ct[i][j])
					cout << Ct[i][j] << " ";
			cout << endl;
		}
		cout << endl;

	}
	return 0;
}
